package com.hytc.controller;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CookieServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if (username != null && password != null){
            Cookie cookie = new Cookie("username", username);
            Cookie cookie2 = new Cookie("password", password);
            cookie.setMaxAge(60*60);
            cookie2.setMaxAge(60*60);
            resp.addCookie(cookie);
            resp.addCookie(cookie2);
            System.out.println("登陆成功");

        } else{
            System.out.println("登陆失败");
        }
    }


}
